//执行顺序 父类静态->子类静态->父类实例->父类构造->子类实例->子类构造.
//动态访问的实现.
class Animal {
    public String name;
    public int age;
    static {
        System.out.println("Animal::static{}");
    }
    {
        System.out.println("Animal::{}");
    }
    public Animal(String name,int age) {
        this.name=name;
        this.age = age;
        System.out.println("public Animal(String name,int age)");
    }
    public void eat() {
        System.out.println(this.name+"正在吃");
    }
}
class Dog extends Animal {
 public String color;
 static {
     System.out.println("Dog :: Static{}");//Dog静态代码块
 }
    {
        System.out.println("Dog::{}");//Dog构造代码块
    }
    public Dog(String name, int age ,String color) {
     //调用父类的带有两个参数的构造方法来初始化父类当中的成员必须在第一行，所以super()和this()不能同时使用
     super(name,age);
     this.color=color;
    /* System.out.println("Dog(String name,int age)");*/
    }
    public void eat() {
        System.out.println(this.name+"正在吃狗粮");
    }
    public void barks() {
        System.out.println(this.name+"  正在汪汪汪...");
    }
}
class Cat extends Animal {
    public String color;
    public Cat(String name,int age,String color) {
        super(name,age);
        this.color=color;
    }
    public void eat() {
        System.out.println(this.name+"正在吃猫粮");
    }
    public void banks() {
        System.out.println(this.name+" 正在喵喵叫");
    }
}
public class Kind {
    public static void main(String[] args) {
        Dog dog = new Dog("旺财",2,"白色");
        dog.barks();//调用子类barks方法
        dog.eat();
        Animal animal = new Dog("阿福",4,"褐色");//向下访问
        animal.eat();//动态访问,调用Animal的eat方法，执行dog的eat方法.
        Cat cat = new Cat("喵喵",3,"黄白色");
        cat.eat();//动态访问.
        cat.banks();
    }
}
